package testJdk.thread.pool.testSqlCallable;

import org.junit.Test;
import testJdk.thread.pool.SinglePoolUtil;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;

/**
 * @ClassName : learn_jdk.threadPoolTest.demo03.WebsocketTest
 * @Description : 类描述
 * Created by cyd on 2021-10-21 17:30:29
 */
public class Test01 {

    @Test
    public void test01() {
        ExecutorService threadPool = SinglePoolUtil.getThreadPool();
        threadPool.execute(() -> {
            System.out.println("ThreadName:" + Thread.currentThread().getName() + ",执行：001");
        });

        threadPool.execute(() -> {
            System.out.println("ThreadName:" + Thread.currentThread().getName() + ",执行：002");
        });
    }

    public static void main(String[] args) {
        ExecutorService threadPool = SinglePoolUtil.getThreadPool();
        TaskTester tester = new TaskTester();
        SqlCallableTask<TaskTester> task = new SqlCallableTask<>(tester, "testExe", 1L);

        Future future = threadPool.submit(task);
        Object o = null;
        try {
            o = future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        System.out.println("future:" + o.toString());
    }

}

class TaskTester {

    public String testExe(Long tId) {
        String result = "tId:" + tId;
        System.out.println(result);
        return result;
    }
}
